package com.li.jiang.Exception;


import com.li.jiang.utils.ReturnMessage;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 **/
@ControllerAdvice
public class GlobalControllerAdvice {


    @ExceptionHandler(TokenException.class)
    @ResponseBody
    public ReturnMessage handle(TokenException exception){
        return ReturnMessage.tokenError(exception.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ReturnMessage handle(RuntimeException exception){
        exception.printStackTrace();
        return ReturnMessage.error("出了某些错误，请稍后再试或联系管理员！");
    }

    @ExceptionHandler(AuthException.class)
    @ResponseBody
    public ReturnMessage handle(AuthException exception){
        exception.printStackTrace();
         return ReturnMessage.authError(exception.getMessage());
    }

    @ExceptionHandler(DataException.class)
    @ResponseBody
    public ReturnMessage handle(DataException exception){
        exception.printStackTrace();
        return ReturnMessage.dataError(exception.getMessage());
    }
}
